Repository navigation
Add regression test for inference recursion hang - #65362
Merged
Ryan Cavanaugh (RyanCavanaugh) merged 1 commit intoNov 6, 2026
Merged
Ryan Cavanaugh (RyanCavanaugh) merged 1 commit into
Ryan Cavanaugh (RyanCavanaugh) merged 1 commit into
Conversation
Relating a generic signature to the signature in the `extends` clause of `ReturnType` instantiates it in the context of that signature. With a recursive, overload-walking type in its return type, inferring between the type arguments of nested instantiations of the same type aliases used to recurse through inferFromTypes and inferFromTypeArguments without terminating. microsoft#64553 fixed this by routing inference from type arguments through invokeOnce, but did not add a regression test for this scenario. The new test times out on the parent of that commit and passes on main.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the inference-recursion regression test and its baselines.
No open issues 🎉
What changed in this PR
Adds compiler regression coverage for the inference recursion hang in #64701, already fixed by the inference caching changes in #64553. No compiler implementation changes are included.
Changes:
- Adds a reduced, dependency-free test that exercises the alias-path recursion guard through
ReturnType<typeof createHandler>. - Records type, symbol, and diagnostic baselines, including the accepted TS2589 depth-limit error rather than a hang.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts |
Adds the reduced inference recursion regression test. |
tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.types |
Records expected inferred types. |
tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.symbols |
Records expected symbol bindings. |
tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.errors.txt |
Records the expected TS2589 diagnostic. |
Review effort: Balanced
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64701
Note
AI disclosure (per CONTRIBUTING.md): I used an AI coding assistant for parts of the investigation, the test reduction and this description. I chose this issue myself, I have reviewed and understood the change, and I will handle review feedback myself.
Analysis
The hang reported in #64701 no longer reproduces on
main. It was fixed by #64553 ("Cache inferences made from type arguments"), which did not add a regression test for this scenario.Verification with the reporter's repro. I ran the equivalent of the reporter's
api-probe.cjsagainst the checker: it requests the return type of every call signature of every expression and its properties.5f5dee5b61, the parent of Cache inferences made from type arguments #64553,getReturnTypeOfSignaturefor the type ofvi.mocked(createHandler)did not return within 60s. The stack matches the one in the issue:inferFromTypes→inferFromTypeArguments→inferFromTypes→ …main, all 980 requests complete in about 0.5s.Root cause. For two instantiations of the same type alias,
inferFromTypesinfers from their type arguments, and does the same for two references to the same generic type. Before #64553 it calledinferFromTypeArgumentsdirectly on both paths. #64553 routes both throughinvokeOnce.invokeOnceskips a source/target pair it has already seen with the same priority and variance, and stops expanding when both sides are deeply nested. In my runs of the reporter's repro, the stack on the parent commit showed the direct calls recursing through nested instantiations of the same aliases.Reduced repro. In the reporter's setup, the hang was reached through the API (
getReturnTypeOfSignature). Theirtsc --noEmitrun did not request that return type. The source-level formReturnType<typeof createHandler>reaches the same code path without external packages:getConditionalType→compareSignaturesRelated→instantiateSignatureInContextOf→applyToReturnTypes→inferFromTypes/inferFromTypeArguments. The test is a reduction of the reporter's repro:type-fest'sIsEqualis kept as is andvitestis removed.Note on the expected TS2589. On
mainthe test terminates with TS2589, which the issue lists as acceptable: "report or bail out at the instantiation and depth limits, not loop". TypeScript 5.9.3 and 6.0.3 check this file without errors, though. In my local experiments the difference appears related to TS7's stable type ordering. I reported that separately in #65365, so it is out of scope for this PR.Fix
There is no compiler change. This PR adds regression coverage for the existing fix: the compiler test
inferFromTypeArgumentsNoInfiniteRecursion.tsand its baselines.5f5dee5b61(before Cache inferences made from type arguments #64553),TestLocal/inferFromTypeArgumentsNoInfiniteRecursiontimes out after 90s inside the same recursion.mainit passes in about 1s.What it covers. I tested this by mutating the two call sites in
inferFromTypesonmain:invokeOnce(..., inferFromAliasTypeArguments)) changed to a direct callinvokeOnce(..., inferFromReferenceTypeArguments)) changed to a direct callSo the test detects removal of the alias-path guard. It does not detect removal of the type-reference-path guard.
Checklist
I successfully ran the applicable commands at the end of my session, and they completed without error: